package cn.melonlib.objects.maps;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;

public class DataMap<K, V> extends LinkedHashMap<K, V> {


    public DataMap(int initialCapacity, float loadFactor) {
        super(initialCapacity, loadFactor);
    }

    public DataMap(int initialCapacity) {
        super(initialCapacity);
    }

    public DataMap() {
    }

    public DataMap(Map<? extends K, ? extends V> m) {
        super(m);
    }

    public DataMap(int initialCapacity, float loadFactor, boolean accessOrder) {
        super(initialCapacity, loadFactor, accessOrder);
    }

    public DataMap<K, V> append(K k, V v) {
        this.put(k, v);
        return this;
    }

    public V get(K k, Supplier<V> defaultValue){
        if(!this.containsKey(k)|| Objects.isNull(this.get(k))){
            this.put(k,defaultValue.get());
        }
        return get(k);
    }


}
